package com.meme.editor.property.value;

import org.apache.log4j.Logger;

import com.meme.editor.property.Property;
import com.meme.editor.property.PropertyFactory;
import com.meme.editor.property.PropertyValue;
import com.meme.editor.property.PropertyControl;
import com.meme.editor.property.control.InputPropertyControl;


public class StringPropertyValue extends PropertyValue
{
	static Logger logger = Logger.getLogger (StringPropertyValue.class);
	
	String mTheValue = "";
	
	public StringPropertyValue (Property property)
	{
		super (property);
	}
	
	@Override
	public Object getValue ()
	{
		return mTheValue;
	}
	
	@Override
	public String toString ()
	{
		return mTheValue;
	}
	
	@Override
	public String getDefaultControlType ()
	{
		return PropertyFactory.ControlType_Input;
	}
	
	@Override
	protected boolean modify (Object newValue)
	{
		if ( newValue == null )
			newValue = "";
		
		if ( newValue instanceof StringPropertyValue )
		{
			StringPropertyValue value = (StringPropertyValue)newValue; 
			
			mTheValue = value.mTheValue;
		}
		else if ( newValue instanceof String )
		{
			mTheValue = (String)newValue;
			
			return true;
		}
		
		logger.assertLog(false, "The newValue may be not a valid string value.");
		
		return false;
	}
	
	@Override
	public String getValueAsString ()
	{
		return mTheValue;
	}
	
	@Override
	protected Object   makeLegalValueFromControl (Object[] params)
	{
		return params[0];
	}
	
	@Override
	protected Object[] makeDataForControl ()
	{
		return new Object[] {toString()};
	}
	
	@Override
	protected boolean _setParameter (String name, Object value)
	{
		return false;
	}
}
